package com.unina.is2.astafantaunina.chat;

import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smackx.muc.MultiUserChat;

import android.util.Log;

public class ChatGruppo {

	//singleton
	private static ChatGruppo chat = null;
	
	public static ChatGruppo getSingletonChatGruppo(XMPPConnection conn, String lega, String username){
		if (chat == null){
			chat = new ChatGruppo(conn, lega, username);
		}
		return chat;
	}
	
	private static MultiUserChat mu;
	private XMPPConnection connection;
	private String lega;
	private String username;
	
	private final static String gruppo = "ASTA@conference.fantaunina";
	
	private ChatGruppo(XMPPConnection conn, String lega, String username){
		this.connection = conn;
		this.lega = lega;
		this.username = username;
		mu = new MultiUserChat(connection, this.lega+gruppo);
	}
	
	public MultiUserChat joinStanza(){
		Log.i("join ", "join stanza "+lega+"ASTA");
		try {
			mu.join(username);
		} catch (XMPPException e) {
			Log.w("errore JOIN", "ERRORE JOIN");
			e.printStackTrace();
		}
		return mu;
	}
	
	public static void exitStanza(){
		Log.i("exit ", "exit stanza");
		mu.leave();
	}
	
	public static void azzeraConnessione(){
		chat = null;
	}
}
